/*************************************************************************************
 *
 *  Revolution Engine
 *  Copyright (C) 2009 Felipe Apablaza
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 ************************************************************************************/

#ifndef __REVENG_OBJRECYCLER_HPP__
#define __REVENG_OBJRECYCLER_HPP__

#include <list>
#include <map>
#include <typeinfo>

namespace RevEng
{
	class IObject;

	class ObjRecycler
	{
	private:
		static ObjRecycler* s_pInstance;

	public:
		static ObjRecycler* Instance();
		static void Delete();

	protected:
		typedef std::list<IObject*> ObjectList;
		typedef std::map<const std::type_info*, ObjectList> ObjectPool;
		ObjectPool m_ObjPool;

	public:
		ObjRecycler();
		virtual ~ObjRecycler();
		
		//Put a free object on the pool.
		void Put(IObject *Obj);

		//Get a new object
		IObject* Get(const std::type_info &ClsInfo);

		//Register a new data type to be recycled
		void Register(const std::type_info &ClsInfo);

		//Unregister that data type.
		//All holded references are deleted.
		void Unregister(const std::type_info &ClsInfo);

		//Query if a type is registered.
		bool IsRegistered(const std::type_info &ClsInfo) const;
	};

	inline ObjRecycler::ObjRecycler()
	{
	}
}

#endif	//__REVENG_OBJRECYCLER_HPP__
